/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package accountproject.model;

import accountproject.WorksComboModel;
import java.util.ArrayList;
import javax.swing.table.TableModel;

/**
 *
 * @author Amon
 */
public class OfferObject {

    private int customerId;
    private String offerId;
    private ArrayList<Detail> details = new ArrayList<Detail>();

    public int getCustomerId() {
        return customerId;
    }

    public void setCustomerId(int customerId) {
        this.customerId = customerId;
    }

    public String getOfferId() {
        return offerId;
    }

    public void setOfferId(String offerId) {
        this.offerId = offerId;
    }

    public void addDetail(Detail detail) {
        details.add(detail);
    }

    public ArrayList<Detail> getDetails() {
        return details;
    }

    public void setDetailsFromTableModel(TableModel model, WorksComboModel comboModel) {
        Detail detail;
        int rowCount = model.getRowCount();
        for (int index = 0; index < rowCount; index++) {
            detail = new Detail();
            if (null == model.getValueAt(index, 0)) {
                break;
            }
            detail.setWorkId(comboModel.getWorkIndex(model.getValueAt(index, 0).toString()));
            detail.setUnitPrice(Double.parseDouble(model.getValueAt(index, 1).toString()));
            detail.setAmount(Integer.parseInt(model.getValueAt(index, 2).toString()));
            detail.setDiscount(Integer.parseInt(model.getValueAt(index, 3).toString()));
            addDetail(detail);

        }
    }
}
